package com.lxm.ymcc.mq.consumer;

import com.alibaba.fastjson.JSON;
import com.lxm.ymcc.dto.PayResultVo;
import com.lxm.ymcc.service.ICourseUserLearnService;
import org.apache.rocketmq.common.message.MessageExt;
import org.apache.rocketmq.spring.annotation.MessageModel;
import org.apache.rocketmq.spring.annotation.RocketMQMessageListener;
import org.apache.rocketmq.spring.core.RocketMQListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

@Component
@RocketMQMessageListener(topic = "payresult-topic",
        selectorExpression="payresult-tags"	//tags
        ,consumerGroup = "service-payres-consumer"
        ,messageModel = MessageModel.BROADCASTING ) //消息的消费模式 CLUSTERING：集群    BROADCASTING：广播
public class PayResultConsumer implements RocketMQListener<MessageExt> {

    @Autowired
    private ICourseUserLearnService courseUserLearnService;
    @Override
    public void onMessage(MessageExt message) {
        byte[] body = message.getBody();
        //数据的转换
        String str= new String(body);
        PayResultVo payResultVo = JSON.parseObject(str, PayResultVo.class);
        courseUserLearnService.addCourseLearn(payResultVo);

    }
}